package com.zh.common.view.shadow

import android.content.Context
import android.graphics.Canvas
import android.os.Build
import android.util.AttributeSet
import androidx.annotation.RequiresApi
import androidx.constraintlayout.motion.widget.MotionLayout

/**
 * @Author: wt
 * @Date: 2021/9/3 10:48
 * @Des: 带阴影背景的MotionLayout
 */
class ShadowMotionLayout @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : MotionLayout(context, attrs, defStyleAttr) {

    private val shadow = ShadowHelper(this)

    init {
        shadow.initAttr(attrs, defStyleAttr)
    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        shadow.onAttachedToWindow()
    }

    @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
    override fun dispatchDraw(canvas: Canvas?) {
        shadow.drawShadow(canvas)
        super.dispatchDraw(canvas)
    }

}